package com.kawa.kemanage.controller.api;


import com.kawa.kemanage.service.NewsLikesService;
import com.kawa.kemanage.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/api/like")
public class NewsLikesController {
    @Autowired
    private NewsLikesService newsLikesService;

    /**
     * 取喜欢
     * @param like_id
     * @return
     */
    @PostMapping("/delectLike/{like_id}")
    public Result delectLike(@PathVariable Integer like_id){
        if (newsLikesService.delectLike(like_id)){
           return Result.success("取消成功");
        }else {
            return Result.error("取消失败");
        }
    }


    /**
     * 根据新闻id查看点赞数
     * @param content_id
     * @return
     */
    @RequestMapping("/getLikeCount/{content_id}")
    public Result getLikeCount(@PathVariable Integer content_id){
        return  Result.success(newsLikesService.getLikeCount(content_id));
    }
}
